﻿using System;
using System.Globalization;
using System.IO;
using System.Text;
using System.Xml;
using Castle.Core.Resource;
using System.Web;

namespace MyLib
{
    internal class MyConfigResource : AbstractResource
    {
        public MyConfigResource()
        {
        }

        public override TextReader GetStreamReader()
        {
            ////这里替换成构造xml文件，里面包含不同模块的services.config
            //StringBuilder sb = new StringBuilder();

            //string[] sz = ModuleUtil.GetModules();
            //if (sz != null)
            //{
            //    foreach (string str in sz)
            //    {
            //        XmlDocument xmldoc = new XmlDocument();
            //        Stream stream = ResourceUtil.GetResourceStream(str, str + ".config.services.config");
            //        if (stream != null)
            //        {
            //            xmldoc.Load(stream);
            //            XmlNode node = xmldoc.SelectSingleNode("//configuration");
            //            if (node != null)
            //            {
            //                sb.Append(node.InnerXml);
            //            }
            //        }
            //    }
            //}
            
            //string xml = "<configuration>" + sb.ToString() + "</configuration>";

            //return new StringReader(xml);       
            string str=HttpContext.Current.Server.MapPath("Config/services.config");
            string xml="<castle><include uri=\"file://Config/services.config\" /></castle>";
            return new StringReader(xml);
        }

        public override TextReader GetStreamReader(Encoding encoding)
        {
            throw new NotSupportedException("Encoding is not supported");
        }

        public override IResource CreateRelative(String relativePath)
        {
            return new ConfigResource(relativePath);
        }


    }
}

